<h2>Why is this an issue?</h2>
<p>When the same code is duplicated in two or more separate branches of a conditional, it can make the code harder to understand, maintain, and can
potentially introduce bugs if one instance of the code is changed but others are not.</p>
<p>Having two <code>Cases</code> in the same <code>Select</code> statement or branches in the same <code>If</code> structure with the same
implementation is at best duplicate code, and at worst a coding error.</p>
<pre data-diff-id="1" data-diff-type="noncompliant">
If a &gt;= 0 AndAlso a &lt; 10 Then
  DoFirst()
  DoTheThing()
ElseIf a &gt;= 10 AndAlso a &lt; 20 Then
  DoTheOtherThing()
ElseIf a &gt;= 20 AndAlso a &lt; 50   ' Noncompliant; duplicates first condition
  DoFirst()
  DoTheThing()
Else
  DoTheRest();
End If
</pre>
<pre data-diff-id="2" data-diff-type="noncompliant">
Select i
  Case 1
    DoFirst()
    DoSomething()
  Case 2
    DoSomethingDifferent()
  Case 3  ' Noncompliant; duplicates case 1's implementation
    DoFirst()
    DoSomething()
  Case Else:
    DoTheRest()
End Select
</pre>
<p>If the same logic is needed for both instances, then:</p>
<ul>
  <li> in an <code>If</code> structure they should be combined </li>
</ul>
<pre data-diff-id="1" data-diff-type="compliant">
If (a &gt;= 0 AndAlso a &lt; 10) OrElse (a &gt;= 20 AndAlso a &lt; 50) Then
  DoFirst()
  DoTheThing()
ElseIf a &gt;= 10 AndAlso a &lt; 20 Then
  DoTheOtherThing()
Else
  DoTheRest();
End If
</pre>
<ul>
  <li> for a <code>Select</code>, the values should be put in the <code>Case</code> expression list. </li>
</ul>
<pre data-diff-id="2" data-diff-type="compliant">
Select i
  Case 1, 3
    DoFirst()
    DoSomething()
  Case 2
    DoSomethingDifferent()
  Case Else:
    DoTheRest()
End Select
</pre>
<h3>Exceptions</h3>
<p>Blocks in an <code>If</code> chain or <code>Case</code> clause that contain a single line of code are ignored.</p>
<pre>
If a &gt;= 0 AndAlso a &lt; 10 Then
  DoTheThing()
ElseIf a &gt;= 10 AndAlso a &lt; 20 Then
  DoTheOtherThing()
ElseIf a &gt;= 20 AndAlso a &lt; 50   ' no issue, usually this is done on purpose to increase the readability
  DoTheThing()
End If
</pre>
<p>But this exception does not apply to <code>If</code> chains without <code>Else</code>-s, or to <code>Select</code>-s without <code>Case Else</code>
clauses when all branches have the same single line of code. In the case of <code>If</code> chains with <code>Else</code>-s, or of
<code>Select</code>-es with <code>Case Else</code> clauses, rule {rule:vbnet:S3923} raises a bug.</p>
<pre>
If a == 1 Then
  DoTheThing() ' Noncompliant, this might have been done on purpose but probably not
ElseIf a == 2 Then
  DoTheThing()
End If
</pre>
<h2>Resources</h2>
<h3>Related rules</h3>
<ul>
  <li> {rule:vbnet:S3923} - All branches in a conditional structure should not have exactly the same implementation </li>
</ul>

